package com.zonski.jbots.desktop.engine;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import com.zonski.jbots.game.entity.InputMind;

public class InputMindKeyListener extends KeyAdapter
{
    private InputMind mind;

    public int up = KeyEvent.VK_UP;
    public int down = KeyEvent.VK_DOWN;
    public int left = KeyEvent.VK_LEFT;
    public int right = KeyEvent.VK_RIGHT;
    public int bomb = KeyEvent.VK_SPACE;
    public int comet = KeyEvent.VK_C;
    public int bombEgg = KeyEvent.VK_1;
    public int wormEgg = KeyEvent.VK_2;
    public int babyEgg = KeyEvent.VK_3;
    public int turretEgg = KeyEvent.VK_4;
    public int tankEgg = KeyEvent.VK_5;

    public InputMindKeyListener(InputMind mind)
    {
        this.mind = mind;
    }

    public void keyPressed(KeyEvent event)
    {
        int keyCode = event.getKeyCode();
        setDown(keyCode, true);
    }

    public void keyReleased(KeyEvent event)
    {
        int keyCode = event.getKeyCode();
        setDown(keyCode, false);
    }

    private void setDown(int keyCode, boolean down)
    {
        if(keyCode == this.up)
        {
            mind.setDown(InputMind.SOUTH, down);
        }else if(keyCode == this.down){
            mind.setDown(InputMind.NORTH, down);
        }else if(keyCode == this.left){
            mind.setDown(InputMind.WEST, down);
        }else if(keyCode == this.right){
            mind.setDown(InputMind.EAST, down);
        }else if(keyCode == this.bomb){
            mind.setDown(InputMind.BOMB, down);
        }else if(keyCode == this.comet){
            mind.setDown(InputMind.COMET, down);
        }else if(keyCode == this.bombEgg){
            mind.setDown(InputMind.BOMB_EGG, down);
        }else if(keyCode == this.wormEgg){
            mind.setDown(InputMind.WORM_EGG, down);
        }else if(keyCode == this.babyEgg){
            mind.setDown(InputMind.BABY_EGG, down);
        }else if(keyCode == this.turretEgg){
            mind.setDown(InputMind.TURRET_EGG, down);
        }else if(keyCode == this.tankEgg){
            mind.setDown(InputMind.TANK_EGG, down);
        }
    }
}
